import { editorRule, indexRule, createRule } from "../validate/template";
import { Application } from "egg";

export default (app: Application) => {
  const { auth, header } = app.middleware;
  const {  jwt, router } = app;

  // router.get('/api/template/preset', app.controller.template.index.doPreset)
  return {
    'template.preset': {
      method: 'GET',
      path: '/api/template/preset',
      options: {
        tags: ['template.preset'],
        description: '模板预制',
        handler: app.controller.template.index.doPreset,

        middlewares: [],
        // validate: indexRule,
      },
    },
    'template.list': {
      method: 'GET',
      path: '/api/template/list',
      options: {
        tags: ['template.list'],
        description: '模板预制',
        handler: app.controller.template.index.list,

        middlewares: [jwt],
        validate: indexRule,
      },
    },
    'template.editor': {
      method: 'GET',
      path: '/api/template/editor',
      options: {
        tags: ['template.list'],
        description: '页面编辑',
        handler: app.controller.template.index.pageTplDetail,

        middlewares: [jwt],
        validate: editorRule,
      },
    },
    'template.save.view': {
      method: 'POST',
      path: '/api/template/save/view',
      options: {
        tags: ['template.save.view'],
        description: '保存模板视图',
        handler: app.controller.template.index.saveTemplateView,

        middlewares: [jwt],
        validate: createRule,
      },
    },
    'template.publish': {
      method: 'GET',
      path: '/api/template/publish/view',
      options: {
        tags: ['template.publish'],
        description: '页面编辑',
        handler: app.controller.template.index.publishTemplateView,
        middlewares: [jwt],
        validate: editorRule,
      },
    },
  }
}